package domainModel;

import java.io.IOException;
import java.io.Serializable;

public class Node implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4932223928768108509L;
	private String id;
	private Node parent;
	private transient String root;
	private String description;

	public Node(String id, Node parent, String description) {
		this.id = id;
		this.parent = parent;
		root = aflaRoot();
		this.description = description;
	}

	public String getId() {
		return id;
	}

	public Node getParent() {
		return parent;
	}

	public String getRoot() {
		return root;
	}

	public void setRoot(String root) {
		this.root = root;
	}

	public String getDescription() {
		return description;
	}

	public String toString() {
		return "ID:" + id + ",Root:" + root + ",Description:" + description;
	}

	public String aflaRoot() {
		Node nod = this;
		while (nod.getParent() != null) {

			nod = nod.getParent();
		}
		return nod.getId();
	}

	private void readObject(java.io.ObjectInputStream stream)
			throws IOException, ClassNotFoundException {

		stream.defaultReadObject();
		root = aflaRoot();

	}

}
